package com.sherllinhe.business.controller.admin;

import com.sherllinhe.business.req.TrainSeatQueryReq;
import com.sherllinhe.business.req.TrainStationQueryReq;
import com.sherllinhe.business.req.TrainStationSaveReq;
import com.sherllinhe.business.resp.TrainSeatQueryResp;
import com.sherllinhe.business.resp.TrainStationQueryResp;
import com.sherllinhe.business.service.TrainStationService;
import com.sherllinhe.common.resp.CommonResp;
import com.sherllinhe.common.resp.PageResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：Sherllin He
 * 日期：2025/4/25 21:10
 */
@RequestMapping("/admin/train-station")
@RestController
public class AdminTrainStationController {
    @Autowired
    private TrainStationService trainStationService;

    @PostMapping("/save")
    public CommonResp<Object> register(@Valid @RequestBody TrainStationSaveReq req){
        trainStationService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainStationQueryResp>> register(@Valid TrainStationQueryReq req){
        PageResp<TrainStationQueryResp> list = trainStationService.queryList(req);
        return new CommonResp<>(list);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        trainStationService.delete(id);
        return new CommonResp<>();
    }
    @GetMapping("/query-by-train-code")
    public CommonResp<PageResp<TrainStationQueryResp>> queryByTrainCode(@RequestParam String trainCode, @Valid TrainStationQueryReq req){
        PageResp<TrainStationQueryResp> list = trainStationService.selectByTrainCode(trainCode,req);
        return new CommonResp<>(list);
    }
}
